fix(schema): widen MusicBrainz Discogs ID columns to BIGINT#376
Merged
Conversation
brainztableinator throws continuous PostgreSQL "integer out of range" errors when processing MusicBrainz releases: discogs_release_id (and its siblings discogs_artist_id, discogs_label_id, discogs_master_id) were declared INTEGER (int4, max 2,147,483,647), but the extractor parses Discogs IDs as i64 and release IDs now exceed 2.1B. Fix both fresh installs and existing databases: - Change the four cross-reference columns to BIGINT in the CREATE TABLE definitions (fresh installs). - Add idempotent `ALTER COLUMN ... TYPE BIGINT` migrations, since CREATE TABLE IF NOT EXISTS is a no-op on pre-existing tables. Neo4j (brainzgraphinator) is unaffected — Neo4j integers are 64-bit. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Contributor
Contributor
Contributor
Contributor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
brainztableinatorthrows continuous PostgreSQLinteger out of rangeerrors (dozens/sec, infinite redelivery loop) when processing MusicBrainz releases in production.Root cause:
schema-init/postgres_schema.pydeclared the Discogs cross-reference columns asINTEGER(int4, max 2,147,483,647), but the extractor parses Discogs IDs asi64(extractor/src/jsonl_parser.rs). Discogs release IDs now exceed 2.1B → overflow onINSERTintomusicbrainz.releases.The same latent risk affected all four sibling columns:
musicbrainz.artistsdiscogs_artist_idmusicbrainz.labelsdiscogs_label_idmusicbrainz.releasesdiscogs_release_idmusicbrainz.release_groupsdiscogs_master_idFix
BIGINTin theCREATE TABLEdefinitions.ALTER TABLE … ALTER COLUMN … TYPE BIGINTmigrations, becauseCREATE TABLE IF NOT EXISTSis a no-op on tables that already exist asINTEGER. Re-applyingTYPE BIGINTto an already-widened column is a no-op, so the migration is safe on every startup.Neo4j (
brainzgraphinator) is unaffected — Neo4j integers are already 64-bit.Tests
test_musicbrainz_discogs_id_columns_are_bigint— asserts the four columns areBIGINT.test_musicbrainz_has_bigint_widening_migrations— asserts the fourALTER COLUMN … TYPE BIGINTmigrations exist.test_musicbrainz_tables_use_if_not_existsandtest_all_statements_create_if_not_existsto recognize that idempotentALTER COLUMN … TYPEmigrations legitimately carry noIF NOT EXISTSclause.All schema-init tests pass;
mypy,ruff, andbanditclean.Notes
This PR is scoped to the schema migration. The related
requeue=Trueamplifier inbrainztableinator.py(which causes non-retriable data-shape errors to redeliver forever) is a separate concern and is not addressed here.🤖 Generated with Claude Code